<%--
  Created by IntelliJ IDEA.
  User: 阿勋
  Date: 2021/7/2
  Time: 14:30
  To change this template use File | Settings | File Templates.
--%>
<%@ page isELIgnored="false" contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<html>
<head>
    <meta charset="utf-8">
    <title>赛事星登录</title>
    <link href="./css/CSS-reset.css" rel="stylesheet"/>
    <link href="./css/jn-question.css" rel="stylesheet"/>
    <link href="./css/login.css" rel="stylesheet"/>

    <script src="./javascript/webConfig.js"></script>
    <script src="./javascript/jquery-1.8.2.min.js"></script>
    <script src="./javascript/jquery.util.js"></script>
    <script src="./javascript/placeholder.js"></script>
    <script src="./javascript/header.js"></script>
    <script src="./javascript/layer.js"></script>
    <script src="./javascript/jsencrypt.min.js"></script>

</head>
<body>
<div class="g-lg-hd">
    <a href="index.jsp" class="u-logo"></a>
</div>
<div class="g-lg-bd">
    <div class="m-lg-box clearfix">
        <div class="banner"><img src="./htmlimg/loging-banner.jpg" width="436" height="541"></div>
        <div class="login-main">
            <ul class="login-top clearfix hd">
                <li class="on"><a href="" id="id0" onclick="showTab(0)" class="person">个人用户登录</a></li>
                <li><a id="id1" href="" onclick="showTab(1)">机构用户登录</a></li>
            </ul>
            <div class="bd">
                <div id="tab0">

                    <ul class="login-person-body">
                        <div class="login-info-height"></div>
                        <form action="<%=request.getContextPath()%>/denglu/login" accept-charset="UTF-8" method="post">
                            <div class="login-line login-line-user">
                                <input type="text" name="user-name" maxlength="40" tabindex="1" value="" size="30"
                                       placeholder="用户名 / 知网个人账号">
                            </div>
                            <div class="login-line login-line-pwd">
                                <input type="password" name="password" tabindex="2" maxlength="20" value="" size="30"
                                       placeholder="密码">
                            </div>
                            <div class="login-line login-line-yanzheng clearfix">
                                <input type="text" tabindex="3" name="validCode" maxlength="4" placeholder="验证码">
                                <div class="img-yanzheng"><img id="yzm0" width="63" height="36"></div>
                                <div class="yanzheng-info">换一个</div>
                            </div>
                            <div class="login-line-help clearfix">

                                <a target="_blank" href="" class="login-forget">忘记密码?</a>
                            </div>
                            <div class="login-button"><input class="u-btn-login" TYPE="submit" value="登录"></div>
                        </form>
                        <div class="clearfix">
                            <div class="fast-login"><span>还没有账号？</span><a href="register.jsp"><span class="register">快速注册</span></a>
                            </div>
                        </div>
                    </ul>
                    <div class="other-login">

                        <div class="button-line clearfix">
                            <div class="info">合作账号登录</div>
                            <a href="" class="lg-qq"></a>
                            <a href="" class="lg-weibo"></a>
                            <a href="" class="lg-wechat"></a>
                        </div>
                    </div>

                </div>
                <input id="userType" type="hidden" name="userType" value="1"/>
                <div id="tab1" style="display:none;">

                    <ul class="login-person-body">
                        <div class="login-info-height"></div>
                        <div class="login-line login-line-user">
                            <input type="text" name="user-name" maxlength="40" tabindex="6" value="" size="30"
                                   placeholder="用户名">
                        </div>
                        <div class="login-line login-line-pwd">
                            <input type="password" name="password" tabindex="7" maxlength="20" size="30" value=""
                                   placeholder="密码">
                        </div>
                        <div class="login-line login-line-yanzheng clearfix">
                            <input type="text" tabindex="8" name="validCode" maxlength="4" placeholder="验证码">
                            <div class="img-yanzheng"><img id="yzm1" width="63" height="36"></div>
                            <div class="yanzheng-info">换一个</div>
                        </div>
                        <div class="login-line-help clearfix">

                            <a target="_blank" href="" class="login-forget">忘记密码?</a>
                        </div>
                        <div class="login-button"><a href="" class="u-btn-login">登 录</a></div>
                        <div class="clearfix">
                            <div class="fast-login"><span>还没有账号？</span><a href=""><span class="register">快速注册</span></a>
                            </div>
                        </div>
                    </ul>
                </div>
            </div>
        </div>
    </div>

    <div class="g-footer clearfix">
        <div class="g-footer-top-line">《中国学术期刊(光盘版)》电子杂志社有限公司 版权所有</div>
        <div class="g-footer-top-line">京ICP证040431号 网络出版服务许可证 (总)网出证(京)字第271号 京公网安备 11010802020460 号</div>


    </div>
</div>

<input type="hidden" id="hUrl" name="hUrl" value="https://saishi.cnki.net/"/>
<input type="hidden" id="hLoginUI" name="hLoginUI" value="1"/>

<script type="text/javascript">
    var jsPublicKey = "-----BEGIN PUBLIC KEY-----MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC8iKgnXm7hTxEr9FcZtBk/xbL8JwSeGpgpGMdd7TgBIARcWXhYeGRP428QYb8//Buls3ZLJAbc4Z8HxFP5yvVMksQEBkR5NyN2Jx3i83jUDX/STLy9ZhCBskNBt1zqtTRw4eEjvmsP5iZ4PyQUXUttyY2Mbjb9AZl87lTlrDCRQwIDAQAB-----END PUBLIC KEY-----";

    function showTab(num) {
        try {
            for (i = 0; i < 2; i++) {
                document.getElementById("tab" + i).style.display = "none";
                document.getElementById("id" + i).parentNode.className = "";
            }

            document.getElementById("tab" + num).style.display = "block";
            document.getElementById("id" + num).parentNode.className = "on";
            //if (num == 1) {
            //    document.getElementById("id" + 0).className = "select";
            //}
            $("#userType").val(num + 1);//设置隐藏input的value值，来判断个人与企业用户
            switchImage();
        } catch (e) {
            alert(e);
        }

    }

    $(document).ready(function () {
        if ($("#userType").val() == "2") {
            showTab(1);
        }
        //setTimeout("switchImage()", 2500)
        switchImage();
        $(".login-info-height").hide();//隐藏错误提示行
    });

    //切换验证码
    function switchImage() {

        var vlocation = "loginperson";//个人
        var idx = 0;
        if ($("#userType").val() == "2") {
            vlocation = "loginenterprise"
            idx = 1;
        }
        //使用这种原生的js，为验证码图片标签赋值比jquery靠谱。
        try {
            document.getElementById("yzm" + idx).src = "https://saishi.cnki.net/passport/api/Captcha/get?w=63&h=36&n=4&vloca=" + vlocation + "&" + Math.random();

        } catch (e) {
            setTimeout("switchImage()", 1000)
            alert("验证码报错啦！！！");
        }
    }


    //点击换一换，获取新验证码
    $(".yanzheng-info").click(switchImage);

    $(".login-line input[type=text],.login-line input[type=password]").keyup(function () {
        var userType = $("#userType").val();
        var index = parseInt(userType) - 1
        try {
            var event = window.event || arguments.callee.caller.arguments[0];
            if (event.keyCode == 13) {
                $(".u-btn-login").eq(index).click();
            }
        } catch (e) {
            alert("出错：" + e);
        }

    });

    var indexLayer = 0;
    //登录提交
    $(".u-btn-login").click(function () {
        var index = $(".u-btn-login").index(this);
        /* var keepName = Boolean($("input[name=keepname]").eq(index).attr("checked"));*/
        var errorMessage = $(".login-info-height").eq(index);
        var userName = $(".login-line-user input[name=user-name]").eq(index).val();


        var password = $(".login-line-pwd input[name=password]").eq(index).val();
        var userType = $("#userType").val();
        var validCode = $(".login-line-yanzheng input[name=validCode]").eq(index).val();


        //校验用户名
        var userNameValiResult = ValidateUserName(userName);
        if (!userNameValiResult.valiPass) {
            errorMessage.addClass('login-info').html(userNameValiResult.message).show();
            return;
        } else {

        }

        //校验密码
        var passwordValiResult = ValidatePassword(password);
        if (!passwordValiResult.valiPass) {
            errorMessage.addClass('login-info').html(passwordValiResult.message).show();
            return;
        } else {

        }
        errorMessage.hide();
        errorMessage.removeClass("login-info").html("");

        /*
        //校验用户名密码的长度
        if (userName.length < 4 || userName.length > 64) {
            errorMessage.addClass('login-info').html("用户名请使用4-64位字符！").show();
            $(".user-name").eq(index).addClass("alert-border");
            return;
        }

        if (password.length < 6 || password.length > 20) {
            errorMessage.addClass('login-info').html("密码请使用6-20位字符！").show();
            $(".password").eq(index).addClass("alert-border");
            return;
        }


        //校验用户名密码是否包含非法字符
        if (IsIllegalChar(userName)) {
            errorMessage.addClass('login-info').html("用户名包含非法字符，不允许登录！").show();
            $(".user-name").eq(index).addClass("alert-border");
            return;
        }
        errorMessage.hide();


        if (IsIllegalChar(password)) {
            errorMessage.addClass('login-info').html("密码包含非法字符，不允许登录！").show();
            $(".password").eq(index).addClass("alert-border");
            return;
        }
        errorMessage.hide();

        //校验用户名必须在合法的字符范围内
        if ((/^[a-zA-Z0-9_]{4,64}$/.test(userName) == false) && (/^([a-zA-Z0-9])+([a-zA-Z0-9_\.\-])*@[A-Za-z0-9]+([-.][A-Za-z0-9]+)*\.[A-Za-z0-9]+([-.][A-Za-z0-9]+)*$/.test(userName) == false)) {
            errorMessage.addClass('login-info').html("用户名请使用4-64位英文字母、数字、下划线！").show();;
            $(".user-name").eq(index).addClass("alert-border");
            return;
        }
        errorMessage.hide();

        //用户名不能为空
        if (!$.trim(userName)) {
            errorMessage.addClass('login-info').html("用户名不能为空！").show();
            $(".user-name").eq(index).addClass("alert-border");
            return;
        }
        else {
            $(".user-name").eq(index).removeClass("alert-border");
        }
        errorMessage.hide();
        //密码不能为空
        if (!$.trim(password)) {
            errorMessage.addClass('login-info').html("密码不能为空！").show();
            $(".password").eq(index).addClass("alert-border");
            return;
        }
        else {
            $(".password").eq(index).removeClass("alert-border");
        }
        */

        if (!$.trim(validCode) || validCode == "验证码") {
            errorMessage.addClass('login-info').html("验证码不能为空！").show();
            return;
        }
        errorMessage.hide();
        errorMessage.removeClass("login-info").html("");

        var encrypt = new JSEncrypt();
        encrypt.setPublicKey(jsPublicKey);


        indexLayer = layer.load(2, {shade: [0.6, '#000']}); //换了种风格
        $.post("https://saishi.cnki.net/passport/api/apiuser/login",
            {
                username: userName,
                password: encrypt.encrypt(password),
                validcode: validCode,
                usertype: userType
                //,keepname: keepName
            }, function (data) {
                if (data.ErrorCode == "E0001") {
                    layer.msg("登录成功");
                    var gourl = $("#hUrl").val();

                    if (userType == 1) {
                        // /ecenter/Center/*******
                        if (gourl.indexOf('/Center/') > 0) {
                            gourl = DomainUrlHelper.WebAction;
                        }

                        //所有个人账号从哪里来，登录后回哪里去
                        if (gourl) {
                            window.location = gourl;
                            return;
                        } else {
                            window.location = DomainUrlHelper.PersonalCenterAction + "Users/Index/" + data.UserGUID;
                        }
                        //手机号验证通过，才能回到登录前页面继续操作
                        //if (data.VeriryTel == 2) {
                        //    if (gourl) {
                        //        window.location = gourl;
                        //        return;
                        //    }
                        //    else {
                        //        window.location = DomainUrlHelper.PersonalCenterAction + "Users/Index/" + data.UserGUID;
                        //    }
                        //}
                        //else {
                        //    window.location = DomainUrlHelper.PassportAction + "Account/BindTel/?retUrl=" + gourl;
                        //}
                    } else {

                        //  /pcenter/*******
                        if (gourl.indexOf('/pcenter/') > 0) {
                            gourl = DomainUrlHelper.WebAction;
                        }

                        if (data.InstituCheckStatus == 0) {//未进入任何的认证页面，需要重头填写认证信息
                            window.location.href = DomainUrlHelper.InstituCenterAction + "Institutioninfo/Attestation?type=&step=1&retUrl=" + gourl;
                        }
                        if (data.InstituCheckStatus == 1) {

                            if (gourl) {
                                window.location = gourl;
                                return;
                            } else {
                                window.location.href = DomainUrlHelper.InstituCenterAction + "Institutioninfo/Attestation?type=" + data.InstitutionType + "&step=" + data.AttestationStep + "&retUrl=" + gourl;
                            }
                        } else if (data.InstituCheckStatus >= 2) {
                            if (gourl) {
                                window.location = gourl;
                                return;
                            } else {
                                window.location = DomainUrlHelper.InstituCenterAction + "Center/Competitions/Manage";
                            }
                        } else {
                            window.location = DomainUrlHelper.WebAction;
                        }
                    }
                } else {
                    layer.close(indexLayer);
                    switchImage();
                    errorMessage.addClass('login-info').html(data.ErrorMessage).show();
                }
            });

    });

    //是否包含非法字符
    function IsIllegalChar(inputValue) {
        var bHaveBadChar = false;
        if (inputValue.indexOf('<') >= 0) {
            bHaveBadChar = true;
        }

        if (inputValue.indexOf('</') >= 0) {
            bHaveBadChar = true;
        }
        if (inputValue.indexOf(' ') >= 0 || inputValue.indexOf('　') >= 0) {
            bHaveBadChar = true;
        }
        if (/[#\$%\^&\*<>/]+/g.test(inputValue)) {
            bHaveBadChar = true;
        }
        return bHaveBadChar;
    }


    ///验证结果
    function ValidResult(bpass, message) {
        this.valiPass = bpass;//bool
        this.message = message;
    }

    //验证用户名
    function ValidateUserName(UserNameVal) {
        var bPassValidate = false;
        var msg = "";
        var userName = UserNameVal;
        if (userName.isNullOrWhiteSpace()) {
            msg = "用户名不能为空！";
        } else if (userName.length < 4 || userName.length > 64) {
            msg = "用户名请使用4-64位字符！";
        } else if (IsIllegalChar(userName)) {
            msg = "用户名包含非法字符，不允许登录！";
        } else if ((/^[a-zA-Z0-9_]{4,64}$/.test(userName) == false) && (/^([a-zA-Z0-9])+([a-zA-Z0-9_\.\-])*@[A-Za-z0-9]+([-.][A-Za-z0-9]+)*\.[A-Za-z0-9]+([-.][A-Za-z0-9]+)*$/.test(userName) == false)) {
            msg = "用户名请使用4-64位英文字母、数字、下划线！";
        } else {
            bPassValidate = true;
            msg = "";
        }
        return new ValidResult(bPassValidate, msg);
    }

    //验证密码
    function ValidatePassword(passwordVal) {
        var bPassValidate = false;
        var msg = "";
        var password = passwordVal;
        if (password.isNullOrWhiteSpace()) {
            msg = "密码不能为空！";
        } else if (password.length < 6 || password.length > 20) {
            msg = "密码请使用6-20位字符！";
        } else {
            msg = "";
            bPassValidate = true;
        }
        return new ValidResult(bPassValidate, msg);
    }

</script>
</body>
</html>










